package com.arpa.oms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.cache.AreaCache;
import com.arpa.ntocc.common.common.cache.PartyCache;
import com.arpa.ntocc.common.common.cache.ShipmentCache;
import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.ntocc.common.common.util.CommonUtil;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.domain.dto.ShipmentAuthorizationJsonBean;
import com.arpa.ntocc.common.domain.dto.WarehouseAuthorizationJsonBean;
import com.arpa.ntocc.common.domain.entity.UserLogin;
import com.arpa.ntocc.common.domain.enums.PartyTypeEnum;
import com.arpa.ntocc.common.domain.vo.TreeData;
import com.arpa.oms.domain.dto.OmsWarehouseDTO;
import com.arpa.oms.domain.entity.OmsWarehouse;
import com.arpa.oms.domain.vo.OmsWarehouseVO;
import com.arpa.oms.mapper.OmsWarehouseMapper;
import com.arpa.oms.service.IOmsWarehouseService;
import com.arpa.wms.cache.WarehouseCache;
import com.arpa.wms.cache.WarehouseShipmentCache;
import com.arpa.wms.cache.WarehouseSpaceCache;
import com.arpa.wms.domain.consts.NumConst;
import com.arpa.wms.domain.consts.PropertyConst;
import com.arpa.wms.domain.dto.InventoryDTO;
import com.arpa.wms.domain.dto.WarehouseDTO;
import com.arpa.wms.domain.entity.Location;
import com.arpa.wms.domain.entity.Warehouse;
import com.arpa.wms.domain.entity.WarehouseSpace;
import com.arpa.wms.domain.enums.DeleteFlagEnum;
import com.arpa.wms.domain.enums.StatusEnum;
import com.arpa.wms.domain.vo.WarehouseShipmentVO;
import com.arpa.wms.domain.vo.WarehouseSpaceVO;
import com.arpa.wms.domain.vo.WarehouseVO;
import com.arpa.wms.mapper.WarehouseMapper;
import com.arpa.wms.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.arpa.wms.domain.consts.CodeConst.WAREHOUSE_CODE;

/**
 * <p>
 * OMS仓库
 * </p>
 *
 * @author wangdong
 * @since 2021-07-21
 */
@Service
public class OmsWarehouseServiceImpl extends ServiceImpl<OmsWarehouseMapper, OmsWarehouse> implements IOmsWarehouseService {


    /**
     * 查询列表
     *
     * @param omsWarehouseDTO
     * @return
     */
    @Override
    public List<OmsWarehouseVO> queryList(OmsWarehouseDTO omsWarehouseDTO) {
        //排序字段名需要驼峰转数据库下划线类型字段名
        if (StringUtils.isNotEmpty(omsWarehouseDTO.getSortField())) {
            omsWarehouseDTO.setSortField(CommonUtil.camel2Underline(omsWarehouseDTO.getSortField()));
        }
        return baseMapper.queryList(omsWarehouseDTO);
    }

    /**
     * 查询合计,包含总数
     *
     * @param warehouseDTO
     * @return
     */
    @Override
    public OmsWarehouseVO queryListSum(OmsWarehouseDTO warehouseDTO) {
        OmsWarehouseVO warehouseVO = baseMapper.queryListSum(warehouseDTO);
        return warehouseVO;
    }


}
